Skip to content

feat(miniapp): 新增微信小程序服务卡片消息接口#3952

Open
Copilot wants to merge 2 commits intodevelopfrom
copilot/add-service-card-message-api
Open

feat(miniapp): 新增微信小程序服务卡片消息接口#3952
Copilot wants to merge 2 commits intodevelopfrom
copilot/add-service-card-message-api

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 7, 2026

微信小程序服务卡片消息(订阅消息2.0)缺少服务端 API 支持。新增 setUserNotifysetUserNotifyExtgetUserNotify 三个接口。

变更

  • URL 常量:在 WxMaApiUrlConstants.Subscribe 中新增三个接口地址
  • 请求/响应 Bean
    • WxMaServiceNotifyRequest:激活与更新服务卡片(含可选的 checkJson 微信支付校验字段)
    • WxMaServiceNotifyExtRequest:更新服务卡片扩展信息
    • WxMaGetUserNotifyRequest / WxMaGetUserNotifyResult:查询卡片状态,响应含 NotifyInfocodeStatecodeExpireTime 等)
  • 接口与实现WxMaSubscribeService 新增三个方法,WxMaSubscribeServiceImpl 对应实现

用法示例

// 激活服务卡片
WxMaServiceNotifyRequest req = WxMaServiceNotifyRequest.builder()
  .openid("oGZUI0egBJY1zhBYw2KhdUfwVJJE")
  .notifyType(1)
  .notifyCode("CODE_FROM_FRONTEND")
  .contentJson("{\"status\":1}")
  .build();
wxMaService.getSubscribeService().setUserNotify(req);

// 查询卡片状态
WxMaGetUserNotifyResult result = wxMaService.getSubscribeService()
  .getUserNotify(WxMaGetUserNotifyRequest.builder()
    .openid("oGZUI0egBJY1zhBYw2KhdUfwVJJE")
    .notifyCode("CODE_FROM_FRONTEND")
    .notifyType(1)
    .build());
// result.getNotifyInfo().getCodeState() — 0:正常, 1:有风险, 2:异常, 10:用户拒收

官方文档:setUserNotify | setUserNotifyExt | getUserNotify

Copilot AI linked an issue Apr 7, 2026 that may be closed by this pull request
实现以下三个服务卡片消息 API:
- 激活与更新服务卡片(setUserNotify)
- 更新服务卡片扩展信息(setUserNotifyExt)
- 查询服务卡片状态(getUserNotify)

Agent-Logs-Url: https://github.com/binarywang/WxJava/sessions/63aeccb8-2684-4ea7-8b6b-9db7d362044a

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Copilot AI changed the title [WIP] Add service card message API for WeChat Mini Programs feat(miniapp): 新增微信小程序服务卡片消息接口 Apr 7, 2026
Copilot AI requested a review from binarywang April 7, 2026 09:20
@binarywang binarywang marked this pull request as ready for review April 11, 2026 12:48
Copilot AI review requested due to automatic review settings April 11, 2026 12:48
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Apr 11, 2026

🤖 Augment PR Summary

Summary: This PR adds server-side support in WxJava MiniApp for WeChat “service card” messages (订阅消息 2.0), covering activation/update, extension update, and status query.

Changes:

  • Added 3 new API URL constants under WxMaApiUrlConstants.Subscribe for service-card operations.
  • Introduced new request/response beans: WxMaServiceNotifyRequest, WxMaServiceNotifyExtRequest, WxMaGetUserNotifyRequest, WxMaGetUserNotifyResult (incl. NotifyInfo).
  • Extended WxMaSubscribeService with setUserNotify, setUserNotifyExt, and getUserNotify.
  • Implemented the new methods in WxMaSubscribeServiceImpl using POST calls and errcode-based error handling.
  • Added TestNG test stubs in WxMaSubscribeServiceImplTest demonstrating basic invocation patterns.

Technical Notes: Requests serialize via WxMaGsonBuilder; the implementation checks errcode and throws WxErrorException on non-zero responses, while getUserNotify deserializes the full result payload.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

String SUBSCRIBE_MSG_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send";

/** 激活与更新服务卡片 */
String SERVICE_NOTIFY_SET_URL = "https://api.weixin.qq.com/wxa/setusernotify";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SERVICE_NOTIFY_*_URL 这三个服务卡片接口地址看起来和官方文档不一致:文档的实际路径是 .../wxa/set_user_notify.../wxa/set_user_notifyext.../wxa/get_user_notify(带下划线),而这里是 setusernotify*,可能会导致调用 404/接口不存在。建议也同步检查并保持 WxMaSubscribeService 中对应的接口 URL 注释一致。

Severity: high

Other Locations
  • weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java:366
  • weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java:369
  • weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSubscribeService.java:125
  • weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSubscribeService.java:138
  • weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSubscribeService.java:151

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 为 weixin-java-miniapp 模块补齐“小程序服务卡片消息(订阅消息 2.0)”服务端能力,在订阅消息相关服务中新增激活/更新卡片、更新扩展信息、查询卡片状态 3 个接口,以便 SDK 用户可直接调用微信开放接口完成服务卡片的生命周期管理。

Changes:

  • WxMaApiUrlConstants.Subscribe 中新增 setusernotify / setusernotifyext / getusernotify 3 个接口 URL 常量
  • 新增对应请求/响应 Bean:WxMaServiceNotifyRequestWxMaServiceNotifyExtRequestWxMaGetUserNotifyRequestWxMaGetUserNotifyResult
  • WxMaSubscribeService 增加 3 个方法,并在 WxMaSubscribeServiceImpl 中实现;测试类中补充了对应测试方法

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java 增加服务卡片相关 API 地址常量,供 Subscribe 服务实现使用
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaServiceNotifyRequest.java 新增激活/更新服务卡片请求体模型与序列化方法
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaServiceNotifyExtRequest.java 新增更新服务卡片扩展信息请求体模型与序列化方法
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaGetUserNotifyRequest.java 新增查询服务卡片状态请求体模型与序列化方法
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaGetUserNotifyResult.java 新增查询服务卡片状态响应模型(含 notify_info 子结构)
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSubscribeService.java Subscribe 服务接口新增 3 个服务卡片方法签名
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSubscribeServiceImpl.java Subscribe 服务实现新增 3 个接口调用与错误码处理逻辑
weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSubscribeServiceImplTest.java 增加 3 个服务卡片接口的测试入口方法

Comment on lines +82 to +86
WxMaServiceNotifyRequest request = WxMaServiceNotifyRequest.builder()
.openid("test_openid")
.notifyType(1)
.notifyCode("test_notify_code")
.contentJson("{}")
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这三个新增测试用例使用了硬编码的占位参数(例如 openid/notify_code),即使提供了真实的 test-config.xml 也大概率会返回微信侧参数错误而导致用例必然失败。建议:1)改为从 TestConfig/WxMaConfig 读取可配置的 openid 等参数,或 2)将该类 API 调用改成 Mockito mock(像 WxMaKefuServiceImplTest 那样)并断言不会抛异常/能正确反序列化,避免依赖真实 notify_code。

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +98
WxMaServiceNotifyExtRequest request = WxMaServiceNotifyExtRequest.builder()
.openid("test_openid")
.notifyType(1)
.notifyCode("test_notify_code")
.extJson("{}")
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该测试方法使用了固定的 "test_openid"/"test_notify_code" 作为参数,会导致集成测试在真实环境中也几乎必然失败(微信侧会校验 openid 与 notify_code 的有效性/归属)。建议改为可配置参数(从 test-config.xml 读取)或改为 mock WxMaService.post 返回 {"errcode":0} 进行单元测试。

Copilot uses AI. Check for mistakes.
Comment on lines +106 to +110
WxMaGetUserNotifyRequest request = WxMaGetUserNotifyRequest.builder()
.openid("test_openid")
.notifyCode("test_notify_code")
.notifyType(1)
.build();
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testGetUserNotify 同样使用占位 openid/notify_code,导致用例在真实调用下基本必然抛 WxErrorException。若目的是验证反序列化结构(notify_info/code_state/code_expire_time),更建议 mock service.post 返回一个包含 notify_info 的固定 JSON,并断言字段解析正确。

Copilot uses AI. Check for mistakes.
@binarywang binarywang added this to the 4.8.3 milestone Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

微信小程序服务卡片消息

3 participants